package com.eques.bean

/**
 * @description
 * @author Create by yc on 2025/10/29/Wed 13:16
 */

import com.eques.demo.R
import java.text.SimpleDateFormat
import java.util.*

data class LockMessage(
    val record_id: String,              // 记录ID
    val identifier: String,             // 标识符
    val create_time: Long,              // 创建时间戳
    val lock_detail_id: String,         // 锁详情ID
    val time: Long,                     // 时间戳
    val state: Int,                     // 消息状态
    val msg_id: String,                 // 消息ID
    val type: Int,                      // 消息类型
    val lock_id: String                 // 设备ID
) {

    /**
     * 获取消息类型描述
     */
    fun getMessageType(): String {
        return when (type) {
            0 -> "默认用户"
            1 -> "密码开锁"
            2 -> "指纹开锁"
            3 -> "卡片开锁"
            4 -> "钥匙开锁"
            5 -> "遥控开锁"
            6 -> "一键开启"
            7 -> "APP开锁"
            8 -> "胁迫开锁"
            9 -> "猫眼开锁"
            10 -> "人脸开锁"
            11 -> "掌纹用户"
            12 -> "虹膜用户"
            13 -> "临时用户"
            14 -> "指静脉开锁"
            15 -> "掌静脉开锁"
            else -> "未知消息"
        }
    }

    /**
     * 获取消息状态描述
     */
    fun getMessageState(): String {
        return when (state) {
            0 -> "未读"
            1 -> "已读"
            2 -> "已处理"
            else -> "未知状态"
        }
    }

    /**
     * 获取消息图标资源
     */
//    fun getMessageIcon(): Int {
//        return when (type) {
//            0 -> R.drawable.ic_launcher_foreground
//            1 -> R.drawable.ic_launcher_foreground
//            2 -> R.drawable.ic_launcher_foreground
//            3 -> R.drawable.ic_launcher_foreground
//            4 -> R.drawable.ic_launcher_foreground
//            5 -> R.drawable.ic_launcher_foreground
//            6 -> R.drawable.ic_launcher_foreground
//            else -> R.drawable.ic_launcher_foreground
//        }
//    }

    /**
     * 获取格式化时间
     */
    fun getFormattedTime(): String {
        val date = Date(create_time)
        val now = Date()
        val diff = now.time - create_time

        return when {
            diff < 60 * 1000 -> "刚刚"
            diff < 60 * 60 * 1000 -> "${diff / (60 * 1000)}分钟前"
            diff < 24 * 60 * 60 * 1000 -> "${diff / (60 * 60 * 1000)}小时前"
            else -> {
                val sdf = SimpleDateFormat("MM月dd日 HH:mm", Locale.getDefault())
                sdf.format(date)
            }
        }
    }

    /**
     * 获取详细时间
     */
    fun getDetailTime(): String {
        val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
        return sdf.format(Date(create_time))
    }

    /**
     * 是否未读
     */
    fun isUnread(): Boolean {
        return state == 0
    }
}

/**
 * 锁消息列表响应数据
 */
data class LockMessageResponse(
    val reason: String,
    val total: Int,
    val code: Int,
    val offset: Int,
    val max: Int,
    val limit: Int,
    val context: String,
    val list: List<LockMessage>
)